﻿using System;
using System.Runtime.Serialization;
using Flatland.GeneticProgramming.CoreTypes;
using Flatland.Utilities;

namespace Flatland.GeneBank {

    /// <summary>
    /// A grow GenoType.
    /// </summary>
    [Serializable]
    public class Grow : GenoType {

        public double growth;
        private bool calcDone;

        /// <summary>
        /// Acts by setting ithe growth from the genes..
        /// </summary>
        /// <param name="msg"></param>
        protected override void Act(ref string msg) {
            if (!calcDone) {
                Execute();
                calcDone = true;
            }
            if ((Agent.MIN_SIZE < Agent.Size + growth && Agent.Size + growth < Agent.MAX_SIZE) && Utils.Random.Next(300) == 1) {//2 was 750
                Agent.UpdateShape(Agent.Vertices(), Agent.Color, (float)(Agent.Size + growth));
            }
        }

        public override double Fitness()
        {
            return 42;
        }

        public override object Clone() {
            return new Grow();
        }

        [Primitive]
        public void GetBig() {
            growth = Math.Abs(growth - float.MaxValue) < 0.01 ? growth : growth + 0.01;
        }

        [Primitive]
        public void GetSmall() {
            growth = Math.Abs(growth - float.MinValue) < 0.01 ? growth : growth - 0.01;
        }


        [Primitive]
        public void GetBigQuick() {
            growth = Math.Abs(growth - float.MaxValue) < 0.01 ? growth : growth + 0.03;
        }

        [Primitive]
        public void GetSmallQuick() {
            growth = Math.Abs(growth - float.MinValue) < 0.01 ? growth : growth - 0.03;
        }

        public Grow(SerializationInfo info, StreamingContext context) {}
        public Grow() { }
    }
}
